import tornado.ioloop
import tornado.web
import tornado.options
from chat.chat import ChatSocketHandler
from tornado.options import define, options, parse_command_line

from chat.msg import MsgHandler

define('port', default=8007, type=int)


class Application(tornado.web.Application):
    def __init__(self):
        handlers = [
            ("/chat/(?P<groupname>.+)", ChatSocketHandler),
            ("/getmsg/(?P<username>.+)",MsgHandler),
        ]
        settings = dict(
            cookiesercet='chatsercet',
            xsrf_cookie=True,
        )
        super(Application, self).__init__(handlers, **settings)


def main():
    tornado.options.parse_command_line()
    app = Application()
    app.listen(options.port)
    tornado.ioloop.IOLoop.current().start()


if __name__ == '__main__':
    main()
